package View

import ControllerView.ControllerView
import com.trolltech.qt.gui._

import AndroidProjectFile.ProjectParameters


/**
 * Created by IntelliJ IDEA.
 * User: danymorard
 * Date: 13.04.11
 * Time: 16:53
 * To change this template use File | Settings | File Templates.
 */

class SecondaryInfoView(controller: ControllerView, parent:QWidget) extends View(controller, parent) {


  protected var labelNameApplication = new QLabel(container)
  protected var labelVersionOs = new QLabel(container)
  protected var labelVersionApp = new QLabel(container)



  var lineEditNameApp = new QLineEdit(container)
  var lineEditVersionApp = new QLineEdit(container)


  var comboxVersionOs = new QComboBox(container)


  protected var labelIconPath = new QLabel(container)
   protected var containerIconPath = new QWidget (container)
  protected var buttonIconPath = new QPushButton(containerIconPath)
  var lineEditIconPath = new QLineEdit(containerIconPath)




  protected var gridLayout = new QGridLayout(container)


  // init View
  this.initView


  /**
   * Initialize the view
   */
  protected def initView {



    // size of the view
    this.setGeometry(OPTION_VIEW_SIZE)


    // set the text
    labelNameApplication.setText("Application name")
    labelVersionApp.setText("Application version")
    labelVersionOs.setText("Android platform")
    labelIconPath.setText("Application icon")


    // edit the button browse
    buttonIconPath.setText("Browse")
    buttonIconPath.setObjectName(CSS_BROWSE_BUTTON)
    buttonIconPath.setFixedSize(SIZE_BUTTON_BROWSE)
    buttonIconPath.clicked.connect(controller, "selectIconPath()")

    // default value of icon
    lineEditIconPath.setText("default ScalaDroid Icon")


    // connection with slots
    comboxVersionOs.activatedIndex.connect(controller, "getMinimumVersion()")
    comboxVersionOs.setFixedWidth(WIDTH_TEXTEDIT)
    lineEditVersionApp.editingFinished.connect(controller, "checkVersionName()")
    lineEditVersionApp.setFixedWidth(WIDTH_TEXTEDIT)

    lineEditNameApp.textChanged.connect(controller, "checkEmptyField()")
    lineEditVersionApp.textChanged.connect(controller, "checkEmptyField()")
    lineEditNameApp.setFixedWidth(WIDTH_TEXTEDIT)


    containerIconPath.setFixedHeight(40)
    containerIconPath.setFixedWidth(WIDTH_TEXTEDIT)
    lineEditIconPath.setGeometry(0,7,300,23)
    buttonIconPath.setGeometry(WIDTH_TEXTEDIT - 80, 6, SIZE_BUTTON_BROWSE.width, SIZE_BUTTON_BROWSE.height)
    buttonIconPath.setObjectName(CSS_BROWSE_BUTTON)



    gridLayout.setColumnMinimumWidth(1,500)

    // create the grid layout
    gridLayout.addWidget(labelNameApplication, 0, 0)
    gridLayout.addWidget(lineEditNameApp, 0, 1)

    gridLayout.addWidget(labelVersionApp, 1, 0)
    gridLayout.addWidget(lineEditVersionApp, 1, 1)

    gridLayout.addWidget(labelVersionOs, 2, 0)
    gridLayout.addWidget(comboxVersionOs, 2, 1)

    gridLayout.addWidget(labelIconPath, 3, 0)
    gridLayout.addWidget(containerIconPath, 3, 1)




  }

  /**
   * Erase all text field
   */
  def eraseTextField{

    lineEditIconPath.clear
    lineEditNameApp.clear
    lineEditVersionApp.clear
  }


  /**
   * Add item to the combox version of the Os Android
   */
  def addVersionOs(listVersion: List[String]) {

    for (strVersion <- listVersion) {
      comboxVersionOs.addItem(strVersion)
    }


  }

  def saveEntries {
    //save entries of first window
    ProjectParameters appName = lineEditNameApp.text
    ProjectParameters versionName = lineEditNameApp.text
  }

}
